package com.gm.baseplatform.core.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.gm.baseplatform.core.utils.ApplicationContextUtil;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @author wangguomei
 * @mail e.wanggm@gmail.com
 * 
 */
public class BaseActionSupport extends ActionSupport {

	private static final long serialVersionUID = -3239745233242007698L;
	
	protected final HttpServletRequest request;
	protected final HttpServletResponse response;	
	
	protected final static String FLAG_LIST = "list";
	protected final static String FLAG_FORWORD = "forword";
	protected final static String FLAG_ADD = "add";
	protected final static String FLAG_DELETE = "del";
	protected final static String FLAG_MODIFY = "mod";
	
	protected String flag;
	
	public BaseActionSupport() {
		this.request = ServletActionContext.getRequest();
		this.response = ServletActionContext.getResponse();
	}
	
	protected HttpServletRequest getHttpRequest() {
		return this.request;
	}
	
	protected HttpServletResponse getHttpResponse() {
		return this.response;
	}
	
	protected AjaxHelper getAjaxHelper() {
		return new AjaxHelper(response);
	}
	
	protected Object getSpringBean(String name) {
		return ApplicationContextUtil.getBean(name);
	}
	
	public String getFlag() {
		return flag;
	}
	
	public void setFlag(String flag) {
		this.flag = flag;
	}
	
	public boolean isAddFlag() {
		return FLAG_ADD.equals(flag);
	}
	
	public boolean isForwordFlag() {
		return FLAG_FORWORD.equals(flag);
	}
	
	public void responseJsonOk(String message) {
		getAjaxHelper().outJSN("{\"code\":1,\"msg\":\""+message+"\"}");
	}
	
	public void responseJsonFailure(String message) {
		getAjaxHelper().outJSN("{\"code\":-1,\"msg\":\""+message+"\"}");
	}
	
	
	
}
